package com.alphaking.Jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.alphaking.bean.Upvote;
import com.mysql.jdbc.PreparedStatement;

public class JdbcUpvote {

	// 数据库连接
	private static Connection con = JdbcUtils.getCon();

	public static List<Upvote> getUpvote(int shareid) {

		List<Upvote> upvotes = new ArrayList<Upvote>();

		String sqlSearch = "select * from upvote where shareid =?";

		try {
			PreparedStatement pstmt = (PreparedStatement) con.prepareStatement(sqlSearch);
			pstmt.setInt(1, shareid);
			ResultSet rst = pstmt.executeQuery();

			while (rst.next()) {
				
				Upvote upvote = new Upvote();
				upvote.setUpvoteAccount(rst.getString("upvote_account"));
				upvote.setUpvoteShareid(rst.getInt("shareid"));
				upvotes.add(upvote);

			}
			pstmt.close();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return upvotes;
	}
}
